package com.jf.blog_jf04.controller;

import com.jf.blog_jf04.bean.Tag;
import com.jf.blog_jf04.data.PageInfo;
import com.jf.blog_jf04.data.dto.TagDto;
import com.jf.blog_jf04.data.ov.TagSearchOV;
import com.jf.blog_jf04.data.ov.TagUpdateOV;
import com.jf.blog_jf04.service.TagService;
import com.jf.blog_jf04.utils.BeanConvertUtils;
import com.jf.blog_jf04.utils.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("/tag")
@RestController
@Api(tags = "标签模块")
public class TagController {
    @Autowired
    private TagService tagService;

    @GetMapping("/page")
    @ApiOperation("分页筛选")
    public R page(PageInfo pageInfo, TagSearchOV ov) {
        return tagService.getPage(pageInfo, ov);
    }

    @GetMapping("/info/{tagId}")
    @ApiOperation("详细信息")
    public R info(@ApiParam("标签编号") @PathVariable int tagId) {
        Tag tag = tagService.getById(tagId);
        return R.success(BeanConvertUtils.copyBean(tag, TagDto.class));
    }

    @PostMapping("/update")
    @ApiOperation("添加或修改")
    public R update(@RequestBody TagUpdateOV ov) {
        tagService.saveOrUpdate(BeanConvertUtils.copyBean(ov, Tag.class));
        return R.success();
    }

    @DeleteMapping("/delete")
    @ApiOperation("删除数据")
    public R delete(@ApiParam("批量删除id") @RequestParam List<Integer> ids) {
        return tagService.delete(ids);
    }

    @GetMapping("/select/{type}")
    @ApiOperation("下拉框数据")
    public R select(@ApiParam(value = "获取数据的类型1全部2当前", allowableValues = "1,2", defaultValue = "1", example = "1") @PathVariable int type) {
        return tagService.getSelect(type);
    }
}
